package controllers

import (
	"classmates/models"
	"strconv"

	beego "github.com/beego/beego/v2/server/web"
)

// HomeWorkController operations for Main
type HomeWorkController struct {
	beego.Controller
}

// URLMapping ...
func (c *HomeWorkController) URLMapping() {
	c.Mapping("Post", c.Post)
}

// 检查学生作业 ...
// @Title checkHomeWork
// @Description 检查学生作业
// @Param	zuoyeNum		path 	int	true		"作业的编号"
// @Param	save		path 	int	false		"是否写入数据库，默认0 不写"
// @Success 200 {string} delete success!
// @Failure 403 id is empty
// @router /checkHomeWork/:zuoyeNum [get]
func (c *HomeWorkController) CheckHomeWork() {
	zuoyeNumStr := c.Ctx.Input.Param(":zuoyeNum")
	zuoyeNum, _ := strconv.Atoi(zuoyeNumStr)
	saveStr := c.Ctx.Input.Param(":save")
	save, _ := strconv.Atoi(saveStr)

	go models.CheckHomeWork(zuoyeNum, save)
	c.Data["json"] = "OK"

	c.ServeJSON()

}
